﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Tyshka.Subroutines.Kernel.Utility
{
    public static class UrlUtility
    {
        public static string GetUrl(string controllerName, string actionName)
        {
            return string.Format("~/{0}/{1}", controllerName, actionName);
        }

        public static string GetUrl(string controllerName, string actionName, Dictionary<string, string> parameters)
        {
            var baseUrl = new StringBuilder();
            baseUrl.AppendFormat("~/{0}/{1}", controllerName, actionName);
            if (parameters != null && parameters.Count > 0)
            {
                Boolean first = true;
                foreach (var parameter in parameters)
                {
                    if (first)
                    {
                        baseUrl.Append("?");
                        first = false;
                    }
                    else
                    {
                        baseUrl.Append("&");
                    }
                    baseUrl.AppendFormat("{0}={1}", parameter.Key, parameter.Value);
                }
            }

            return baseUrl.ToString();
        }
    }
}
